package com.nanjing.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	
	private static final String url = "jdbc:oracle:thin:@localhost:1521:orcl" ;
	private static final String driver = "oracle.jdbc.driver.OracleDriver" ;
	private static final String uname = "anyanqing" ;
	private static final String password = "123" ;
	
	public static Connection getConnection(){
		Connection conn = null ;
		try {
			Class.forName(driver) ;
			conn = DriverManager.getConnection(url,uname,password) ;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn ;
	}
	
	public static void free(Connection conn, PreparedStatement ps, ResultSet rs){
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(ps != null){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(conn !=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	/*public static void main(String[] args) {
		Connection conn = getConnection() ;
		System.out.println(conn);
	}*/
}
